layui.use(['layer', 'form', 'formX', 'setter', 'mynotice', 'admin', 'ax', 'util', 'dataGrid', 'element'], function () {
    var $ = layui.jquery;
    var layer = layui.layer;
    var form = layui.form;
    var formX = layui.formX;
    var setter = layui.setter;
    var mynotice = layui.mynotice;
    var admin = layui.admin;
    var $ax = layui.ax;
    var util = layui.util;
    var dataGrid = layui.dataGrid;
    var element = layui.element;
    
    var Vote = {
    	ins: {},
    	dataGridRender:() => { // 渲染数据列表
    		Vote.ins = dataGrid.render({
    	        elem: '#reslistVoteGrid',  // 容器
    	        templet: '#lires2',  // 模板
    	        url: '/api/zp/vote/list',  // 数据接口
    	        page: {limit: 20},  // 开启分页
    	        where:{userId: $('#authuserid').val()},
    	        done: function(res, curr, count){
    	        	$('#userVoteNumber').text(count);	
    	        	$('.wall').jaliswall({item: '.article'});
    	        }
    	    });
    		
    	}
    }
    Vote.dataGridRender();
    dataGrid.on('tool(reslistVoteGrid)', function (obj) {
    	var data = obj.data;
    	var id = $(this).data('id');
        if (obj.event === 'unvote') {
        	mynotice.load('请稍后');
    	    var ajax = new $ax('/api/zp/vote_cancel/' + id, 'post', function (res) {
    	    	mynotice.destroy();
    	    	Vote.ins.reload({page: {curr: $(".layui-laypage-em").next().html()}});
            }, function (res) {
            	mynotice.destroy();
            	mynotice.error(res.msg);
            });
            ajax.start();
        }
    });
    
});